<?php $this->load->module('mobile/index/header', $common);?>
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/dialog.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/base.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/index.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/line.css" />
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/mobilecommon.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/slider.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/dialog.js"></script>
<style>
    .container{

        width:100%;
    }

    .w-item{

        background:#fff;
        color:#666666;
    }

    .writeok, .in-item dd input.writeok{
        color:#666666;
    }

    .btnle{
        width:60%;
        height:2rem;
        background-color:#349cd1;
        border-radius:5px;
        color:#ffffff;
        font-size:1rem;
        font-weight:bold;
        line-height:2rem;
        display:block;
        text-align:center;
        margin:0 20%;
        margin-top:0.5rem;
    }

    .col_div{
        margin-top:0;
        background:#f2f2f2;
        padding:10px 10px 30px 10px;
        border-top:9px solid #c8c9ca;
    }
    .col_div .user-tips{color: #349cd1;text-align:center;font-size:.6rem;}
    .col_div .global-price{text-align:center;font-size:1rem;margin-top:25px;}
    .col_div .global-price .font-orange{font-size:1.6rem;font-weight:bold;padding-left:15px;}
</style>
<div class="container">
    <div class="line-order-layer line-order-head-content">
           <div class="head-title-box">
               <div class="item-layer">
                <h1><?php echo $row['line_name']?></h1>
                <p><?php echo $company;?></p>
               </div>
           </div>
           <div class="head-city-box">
                <div class="item-layer">
                <p><?php echo $row['chufa_city'];?>出发：<?php echo $row['short_name']?> <?php echo $sort_name;?></p>
                </div>
           </div>
          <div class="head-date-box">
               <div class="item-layer">
               <span class="date-title">发团日期:</span>
               <span class="go-date">
               <select name="date" id="goDate">
                    <option value="0">请选择团期</option>
                  <?php foreach($go as $k=>$v):?>
                      <option value="<?php echo $v['go_id'];?>"><?php echo $v['go_date'];?></option>
                  <?php endforeach ; ?>
               </select>
               </span>
               </div>
          </div>
    </div>
    <div class="line-order-layer line-order-date-content"></div>
    <div class="w-item" style="  border-bottom: 1px solid #c8c9ca;padding:.5rem 1.3rem;">
        <dl class="in-item fn-clear">
            <dt>联系人</dt>
            <dd><input type="text" name="name" placeholder="请填写联系人姓名" value="" class="writeok"></dd>
        </dl>
    </div>
    <div class="w-item marginTop" style="padding:.5rem 1.3rem;">
        <dl class="in-item fn-clear borderTop">
            <dt>手机号</dt>
            <dd><input type="tel" name="phone" maxlength="11" placeholder="免费接收订单确认短信" value="" class="writeok"></dd>
        </dl>
    </div>

    <input type="hidden" value="0" name="go_id">
    <input type="hidden" value="<?php echo $row['line_id'];?>" name="line_id">
</div>
<div class="col_div">
<!--    <h3 class="user-tips">请在提交前确认您已阅读</h3>-->
    <p class="global-price">订单总额:<span class="font-orange" >¥<span id="price">0</span></p>
    <a href="javascript:void(0);" class="btnle btn_submit" title="提交订单">提交订单</a>
</div>
<?php $this->load->module('mobile/index/footer',$common);?>
<script type="text/javascript">
    <?php if($go[0]['go_id']){?>
    $('#goDate').val('<?php echo $go[0]['go_id']?>');
    changeGodate($('#goDate'));
    <?php }?>
    function alert_popup(text){
        $.dialog({
            style:'tip',
            width:200,
            closeTime:1000,
            content: '<p style="text-align: center">'+text+'</p>'
        }).open();
    }

    function total_price(){
     var pay = 0 ;
     $('.go-price').each(function(){
         var price = $(this).attr('price');
         var num =   $(this).val();
         pay = price*num + pay  ;
     })
     $('#price').empty().text(pay.toFixed(2));
    }

    $(function(){
        var slid = $("#sliderimg").slider({
            loop: true
        });

        $('.btn_submit').click(function(){

            if($('select[name="date"]').val()== 0){
                alert_popup('请选择团期');
                return false;
            }

            var price_id = new Array();
            var go_num = new Array();
            var totla_num = 0;
            $('.go-price').each(function(i){
                price_id.push($(this).attr('price_id'));
                go_num.push($(this).val());
                totla_num = parseInt( parseInt($(this).val()) + totla_num)  ;
            })

            if(totla_num == '0') {
                alert_popup('出行人数必须>0');
                return false;
            }

            price_id = price_id.join(",");
            go_num = go_num.join(",");


            if($('input[name="name"]').val().length == 0){
                alert_popup('请输入姓名');
                return false;
            }

            if($('input[name="phone"]').val().length == 0){
                alert_popup('请输入手机号');
                return false;
            }else {
                var $val = $("input[name='phone']").val();
                var length = $val.length;
                var status = (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(14[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test($val));
                if(status==false){
                    alert_popup('请正确填写您的手机号码');
                    return false;
                }
            }



            var line_id = $('input[name="line_id"]').val();
            var go_id = $('input[name="go_id"]').val();
            var name  = $('input[name="name"]').val();
            var phone  = $('input[name="phone"]').val();


            $.post('<?php echo $form_url ;?>',{
                go_id: go_id,
                line_id: line_id,
                price_id: price_id,
                go_num: go_num,
                name: name,
                phone: phone
            },function(data){
                alert_popup(data.info);
                if(data.status=='1')
                {
                    setTimeout(function(){
                        window.location.href='<?php echo site_url('mobile/order/profile/')?>'+'&id='+data.order_id;
                    }, 1200);
                }
            },'json')
        })


        $('#goDate').change(function(){
            changeGodate($(this));
        });
    });


    function changeGodate(obj){
        var goid = obj.val();
        if(goid=='0'){
            $('.go-box').remove();
            $('#price').empty().text('0');
            return false ;
        }
        $('input[name="go_id"]').val(goid);
        $.post('<?php echo $go_url ;?>',{
            goid: goid
        },function(data){
            if(data.length>0){
                var html = '<div class="w-item go-box">';
                for(var i =0;i<data.length;i++){
                    var item = data[i];
                    html += '<dl class="in-item-number fn-clear"><dt>'+item.price_name+
                        '<span class="font-blue">¥'+item.ws_price+'/人</span></dt>'+
                        '<dd><span class="btn min_order"></span>'+
                        '<input type="tel" class="ipt-numbers notice go-price" maxlength="3"  '+
                        'price="'+item.ws_price+'" value="1" price_id="'+item.price_id+'" readonly>'+
                        '<span class="btn plus_order"></span>'+
                        '</dd></dl>' ;
                }
                html +='</div>';
                $('.go-box').remove();
                $('.line-order-date-content').html(html);
                total_price();
            }

            var storeNum = 0;
            var $min_order = $('.min_order');
            $min_order.on('click',function(){
                var obj = $(this).siblings('input');
                var price =  parseInt(obj.attr('price'));
                if(obj.val() === ''){
                    return false;
                }
                var num = parseInt(obj.val());
                if(num>0){
                    obj.val(--num);
                }
                storeNum = num;
                total_price();
            })


            var $plus_order = $('.plus_order');
            $plus_order.on('click',function(){
                var obj = $(this).siblings('input');
                var price =  parseInt(obj.attr('price'));
                if(obj.val() === ''){
                    return false;
                }
                var num = parseInt(obj.val());
                obj.val(++num);
                total_price();
            })
        },'json')
    }
</script>